import { Auth } from '@/store/reducer/user';

export const TOKEN_KEY = 'itcast-geek-park-h5';
// 读取
export const getToken = (): Auth => {
  // 💥 注意有可能取出是null，需要使用字符串'{}'做逻辑或
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}');
};
// 删除

export const removeToken = (): void => {
  localStorage.removeItem(TOKEN_KEY);
};

// 设置
export const setToken = (auth: Auth) => {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(auth));
};

// 判断
export const hasToken = (): Boolean => {
  return !!getToken().token;
};
